import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class FourthFactory1 {
    static Map<String,String> map = new HashMap<>();
    static {
        //创建properties对象，来解析properties文件
        Properties properties = new Properties();
        //二阶段输入流通过上面来读取？
        InputStream resourceAsStream = FourthFactory1.class.getResourceAsStream("applicationContext.properties");
        String personName ;
        try {
            //需要加载读取我们的配置文件
            properties.load(resourceAsStream);
            Set<Object> keys = properties.keySet();
            for (Object key : keys) {
                //这里是value
                personName = properties.getProperty(key + "");
                //把对应的k-v放入map集合中
                map.put(key + "", personName);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public Object getBean(String name){
        String className = map.get(name);
        Object o = null;
        try {
            Class<?> aClass = Class.forName(className);
            o = aClass.newInstance();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return o;
    }
}
